<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        debugger
        function getSomething() {
         var r = 0;
         setTimeout(function() {
         r = 2;
         }, 10);
         return r;
        }
        
        function compute() {
         var x = getSomething();
         alert(x * 2);
        }
        compute();
        
        // setTimeout(function() {
        //  console.log(r)
        //  }, 1000);

        function getSomething(a) {
            var r = 0;
            console.log(a)
            setTimeout(function() {
                r = 2;
                a(r);
            }, 10);
        }
        
        function compute(x) {
            alert(x * 2);
        }
        getSomething(compute);
        
        </script>
        
        
</body>
</html>